/*
 *  Phrase.cpp
 *  OfflineTranslator
 *
 *  Created by PH on 5.9.10.
 *  Copyright 2010 Petr Homola. All rights reserved.
 *
 */

#include "stdafx.h"
#include "Phrase.h"
#include "PhrasePath.h"

namespace nlp {
	
	void Phrase::linearize(const string& prefix, const PhrasePath* path, BLOCKVAR(block, void, const string&)) const {
		shared_ptr<AVM> _avm = avm;
		assert(_avm != NULL);
		while (_avm != NULL) {
			string _prefix = prefix.size() > 0 ? prefix + " " : "";
			_avm->linearize(BLOCK(path, block, _prefix)(const string& result) {
				//cout << "########## " <<  (_prefix + result) << endl;
				if (path == NULL) block(_prefix + result);
				else path->linearize(_prefix + result, block);
			}, false);
			_avm = _avm->getAlternativeAvm();
		}
	}
	
}
